<#assign pojo=oneToManyPojo.getOne()>
<#assign many=oneToManyPojo.getMany()>
<#assign ones=oneToManyPojo.getOnes()>
<#assign fields=pojo.getFilterdPojoFields()>
<#assign declarationName = pojo.importType(pojo.getDeclarationName())>
<#assign declarationNameFirstLetterLower = pojo.importType(pojo.getDeclarationNameFirstLetterLower())>
<#assign realPackageAndClassPath = "${pojo.getRealPackageAndClassPath()}">
<#assign masterid = pojo.getDeclarationNameFirstLetterLower()+"Id">
'use strict';

app.factory('${declarationName}Service', ['$resource', '$q', 'AngularUtils', function ($resource, $q, AngularUtils) {
    var base_url = '/eit-api/${declarationNameFirstLetterLower}/';
    var service = {};
    service.get${declarationName}Detail = function (id, onSucess, onFail) {
        if (id == null) {
            erro("查询的FILINGID不能为空")
        }
        AngularUtils.get(base_url + "findById", {id:id}, onSucess, onFail);
    };
    service.save${declarationName} = function (entity, onSucess, onFail) {
        // console.log(entity)
        if (entity != null) {
            if (entity.id != null) {
                // console.log(1)
                AngularUtils.save(base_url + "update", entity, onSucess, onFail);
            } else {
                // console.log(2)
                AngularUtils.save(base_url + "new", entity, onSucess, onFail);
            }
        } else {
            erro("保存的信息不能为空");
        }
    };
    service.delete${declarationName} = function (entity, onSucess, onFail) {
        // console.log(entity)
        if (entity != null) {
            if (entity.id != null) {
                AngularUtils.delete(base_url + "deleteById" , {id:id}, onSucess, onFail);
            } else {
                erro("删除的数据还没有保存");
            }
        } else {
            erro("保存的信息不能为空");
        }
    }
    service.find${declarationName}ByList = function (params, onSucess, onFail) {
        AngularUtils.get(base_url + "findByList", params, onSucess, onFail);
    };
    service.find${declarationName}ByPage = function (params, onSucess, onFail) {
        AngularUtils.get(base_url + "findByPage", params, onSucess, onFail);
    };
    return service;
}]);